#!/bin/bash
#1. 判断参数个数
if [ $# -lt 1 ]
then
  echo Not Enough Arguement!
  exit;
fi
#2. 遍历所有文件
for file in "$@"
do
  #4. 判断文件是否存在
  if [ -e "$file" ]
  then
    #5. 获取父目录
    parent_dir=$(cd -P $(dirname "$file"); pwd)
    #6. 获取当前文件的名称
    filename=$(basename "$file")
    xcall "mkdir -p $parent_dir"
    xcall "rsync -aq $HOSTNAME:$parent_dir/$filename $parent_dir"
  else
    echo "$file" does not exists!
  fi
done

